package com.system.role.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.system.role.dao.RoleRepository;
import com.system.role.entity.Role;
@Service
@Transactional
public class RoleService implements IRoleService {
	@Autowired	
	private RoleRepository roleRepository;
	
	public void saveOrUpdate(Role role) {
		roleRepository.save(role);
	}
	public void delete(Role employee) {
		roleRepository.delete(employee);
	}
	public void delete(List<Long> ids) {
		List<Role> employee =  (List<Role>) roleRepository.findAll(ids);
		if(employee!=null) {
			roleRepository.delete(employee);
		}
	}
	@Transactional(readOnly = true)
	public Role findOne(Long roleId) {
		return roleRepository.findOne(roleId);
	}
	@Transactional(readOnly = true)
	public List<Role> findAll(){
		return (List<Role>) roleRepository.findAll();
	}
	//动态条件查询
	@Transactional(readOnly = true)
	public Page<Role> findAll(Specification<Role> spec, Pageable pageable){
		return roleRepository.findAll(spec, pageable);
	}

	
}
